package nl.sogyo.objectvisualisatie.data;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.sun.jdi.Field;
import com.sun.jdi.Method;

/**
 * An ObjectInfo object contains all kind of information about one
 * object (from the application that is monitord) that is created in the JVM.
 * 
 * @author ben dhont
 *
 */

public class ObjectInfo {
	
	private String className; 					// Class name of the object
	private int id;								// unique id of the object (given by the JVM)
	private HashMap<Field, Object> fields; 		// All fields and and values of an object
	private List<Method> methods; 				// All methods of an object
	private ArrayList<Integer> relations;		// All relations to other objects
	private ArrayList<Integer> initialisations;	// All initializations that this object has performed
	
	/*Visualization INFO*/
	private float width = 10; 					// Width of the object in the diagram
	private float topHeight = 1;				// Height of the space for the object name
	private float height = 1;					// Default height of the field-square of the object
	private float fieldHeight = 0.7f;			// Height that the fieldsquare will grow for each field
	private float x, y, z;						// X, Y and Z-coordinate of the object in the diagram
	private boolean selected;					// Boolean if this object is selected in objectList

	/**
	 * Constructor
	 */
	public ObjectInfo(String className, int id)
	{
		this.className = className;
		this.id = id;
		relations = new ArrayList<Integer>();
		initialisations = new ArrayList<Integer>();
		fields = new HashMap<Field, Object>();
		methods = new ArrayList<Method>();
	}

	/**
	 * Add a field to the objectInfo
	 * @param field = field that will be added
	 * @param value = value of the field
	 */
	public void addField(Field field, Object value)
	{
		fields.put(field, value);
	}
	
	/**
	 * Get all fields
	 * @return
	 */
	public HashMap<Field, Object> getFields()
	{
		return fields;
	}
	
	/**
	 * Add a relation to the object
	 * @param objectId = id of the object that has a relation with this object
	 */
	public void addRelation(int objectId)
	{
		relations.add(objectId);
	}
	
	/**
	 * Get all relations
	 * @return
	 */
	public ArrayList<Integer> getRelations()
	{
		return relations;
	}
	
	/**
	 * Remove all relations
	 */
	public void removeRelations()
	{
		relations.clear();
	}
	
	/**
	 * Add an initialization (this object created object X)
	 * @param objectId
	 */
	public void addInitialisation(int objectId)
	{
		initialisations.add(objectId);
	}
	
	/**
	 * Get all initializations
	 * @return
	 */
	public ArrayList<Integer> getInitialisations()
	{
		return initialisations;
	}
	
	public float getWidth() {
		return width;
	}

	public void setWidth(int width) {
		
		this.width = width;
	}

	public float getHeight() {
		if(fields.size() > 1) this.height = fields.size() * fieldHeight; //calculate height
		else this.height = 1.0f;
		return height;
	}

	public float getFieldHeight() {
		return fieldHeight;
	}

	public void setFieldHeight(float fieldHeight) {
		this.fieldHeight = fieldHeight;
	}

	public String getClassName() {
		return className;
	}
	public int getId() {
		return id;
	}
	
	public float getX() {
		return x;
	}

	public void setX(float x) {
		this.x = x;
	}

	public float getY() {
		return y;
	}

	public void setY(float y) {
		this.y = y;
	}

	public float getZ() {
		return z;
	}

	public void setZ(float z) {
		this.z = z;
	}
	
	public float getTopHeight() {
		return topHeight;
	}
	
	public boolean isSelected() {
		return selected;
	}

	public void setSelected(boolean selected) {
		this.selected = selected;
	}
		
	public List<Method> getMethods() {
		return methods;
	}

	public void setMethods(List<Method> methods) {
		this.methods = methods;
	}
}
